﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VoiceAd.Models;
using System.Text;
using VoiceAd.DAL;

namespace VoiceAd.Controllers
{
    public class HomeController : MultiLangController
    {
        private IServicesRepository servicesRepository = new ServicesRepository(new dbVoiceAdDataContext());
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            subMenuServices();

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult LienHe()
        {
            subMenuServices();
            return View();
        }

        public void subMenuServices()
        {
            StringBuilder str = new StringBuilder();
            str = str.AppendLine("<ul>");
            IEnumerable<tblServices> lstServices = servicesRepository.GetListService();
            foreach (tblServices tbl in lstServices)
            {
                string lUrl = Url.Content("~/service-" + VoiceAd.Common.UrlEncode.ToFriendlyUrl(tbl.Title_Vn) + "-" + tbl.Id.ToString() + ".html");
                str.AppendLine("<li><a href=" + lUrl + ">" + tbl.Title_Vn + "</a></li>");
            }
            str = str.AppendLine("</ul>");
            ViewBag.lstSubMenu = str.ToString();
        }

        protected override void Dispose(bool disposing)
        {
            servicesRepository.Dispose();
        }
    }
}
